#include <iostream>
#include <vector>
using namespace std;

int max_v_recur(vector<int> &v, int n, int m)
{
        if(n == 0){
                return 0;
        }

        int max_v = max_v_recur(v, n - 1, m);
        if(m >= v[n]){
                max_v = max(max_v, max_v_recur(v, n - 1, m - v[n]) + v[n]);
        }

        return max_v;
}

int max_v_dp(vector<int> &v, int n, int m)
{
        vector<int> dp(m + 1, 0);
        for(int i = 1; i <= n; i++){
                for(int j = m; j >= v[i]; j--){
                        dp[j] = max(dp[j], dp[j - v[i]] + v[i]);
                }
        }
        return dp.back();
}


int main()
{
        int v, n;
        cin>>v>>n;
        vector<int> vi(n + 1, 0);
        for(int i = 1; i <= n; i++){
                cin>>vi[i];
        }

        int max_v = max_v_dp(vi, n, v);
        cout<<v - max_v<<endl;

        return 0;
}